/**
 * https://leetcode-cn.com/problems/minimum-genetic-mutation
 * @param {string} start
 * @param {string} end
 * @param {string[]} bank
 * @return {number}
 */
 var minMutation = function(start, end, bank) {
  let min = -1;
  const genes = ['A', 'C', 'G', 'T'];
  const visited = new Set();
  function dfs (current, level) {
      // terminator
      if (current === end) {
          min = min === -1 ? level : Math.min(min, level);
          return;
      }
      // process;
      visited.add(current);
      for (let i = 0; i < current.length; i++) {
          const arr = current.split('');
          for (let j = 0; j < genes.length; j++) {
              // prune
              if (genes[j] === arr[i]) {
                  continue;
              }
              arr[i] = genes[j];
              const newString = arr.join('');
              if (visited.has(newString)) {
                  continue;
              }
              if (!bank.includes(newString)) {
                  continue;
              }
              // drill down
              dfs(newString, level + 1);
          }
      }
      
  }
  dfs(start, 0);
  return min;
};